package me.jiatao.taobaotools.activity;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.bilibili.boxing.Boxing;
import com.bilibili.boxing.model.config.BoxingConfig;
import com.bilibili.boxing.model.entity.BaseMedia;
import com.bilibili.boxing_impl.ui.BoxingActivity;

import java.util.List;

import me.jiatao.taobaotools.Constants;
import me.jiatao.taobaotools.R;
import me.jiatao.taobaotools.utils.ShowMessageUtils;

public class MainActivity extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        performCodeWithPermission("申请权限",
                new UOPermissionCallback() {
                    @Override
                    public void hasPermission() {
                        ShowMessageUtils.show(activity, "授权成功");
                    }

                    @Override
                    public void noPermission() {
                        ShowMessageUtils.show(activity, "授权失败");
                    }
                },
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.READ_PHONE_STATE);

    }

    public void selectBg(View view) {
        BoxingConfig config = new BoxingConfig(BoxingConfig.Mode.SINGLE_IMG); // Mode：Mode.SINGLE_IMG, Mode.MULTI_IMG, Mode.VIDEO
//        config.needGif().withMaxCount(9)
//                .needCamera(cameraRes)// camera, gif support, set selected images count
//                .withMediaPlaceHolderRes(resInt) // set the image placeholder, default 0
//                .withAlbumPlaceHolderRes(resInt) // set the album placeholder, default 0
//                .withVideoDurationRes(resInt) // set the video duration resource in video mode, default 0

        // start thumbnails Activity, need boxing-impl.
        Boxing.of(config).withIntent(this, BoxingActivity.class).start(this, Constants.SELECT_IMG_REQUEST_CODE);
    }

    public void findFriend(View view) {
        Intent intent = new Intent(this, FriendActivity.class);
        startActivity(intent);
    }


    public void evaluateProduct(View view) {
        Intent intent = new Intent(this, ProductActivity.class);
        startActivity(intent);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == Constants.SELECT_IMG_REQUEST_CODE) {
            List<BaseMedia> medias = Boxing.getResult(data);
            if (medias != null && medias.size() > 0) {
                String imagePath = medias.get(0).getPath();

                if (TextUtils.isEmpty(imagePath)) {
                    ShowMessageUtils.show(this, "图片路径为空!");
                    return;
                }
                Intent intent = new Intent(this, EditActivity.class);
                intent.putExtra("IMG_PATH", imagePath);
                startActivity(intent);
            }
        }
    }

}
